const flags = {
  bidSpace: {
    name: '竞价空间偏差',
    reason:
      '【省内竞价空间】日前预估与实时存在偏差，导致最终形成的现货价格不一致。由于竞价空间的评估涉及多类数据源，各数据源对偏差主导作用如下：',
    reasonList: [
      '1.新能源预测偏差：占比__energy',
      '2.联络线预测偏差：占比__concact',
      '3.省内负荷预测偏差：占比__load',
    ],
  },
  quotedPrice: {
    name: '报价曲线偏差',
    reason:
      '【全省非市场化机组报价曲线】日前与实时在一些时点产生较大偏离，导致部分时点价格背离。该曲线日前实时不一致的成因有多种：',
    reasonList: [
      '1.日内调度行为变化，有临时启停机等操作',
      '2.市场化运行数据披露不全，如分布式新能源数据',
      '3.其它诸如关键通路临时故障等',
    ],
  },
  settlePrice: {
    name: '结算价格修正',
    reason:
      '当日均价超过阈值时，会采用均值拉动法修正全天出清价格，该修正方法会对价差方向产生一定影响。',
    reasonList: [],
  },
};
export default () => {
  const fmtPer = (v) => (((v) => !!v === 0) ? `${(v * 100).toFixed(0)}%` : '-');
  const fmtPrice = (v) => (!!v || v === 0 ? v.toFixed(2) : '-');
  const fmtReason = (v, record) => {
    const { reason, reasonList } = flags?.[record.reasonFlag] || {};
    return (
      <div>
        <div>{reason}</div>
        {reasonList.map((x, i) => {
          const [label, key] = x.split('__');
          return (
            <div key={i}>
              {label}
              {key && <span>{fmtPer(record?.reason?.[key])}</span>}
            </div>
          );
        })}
      </div>
    );
  };
  return [
    {
      code: 'reasonFlag',
      name: '直接原因',
      width: 80,
      lock: true,
      align: 'center',
      render: (v) => flags?.[v]?.name || '',
    },
    {
      code: 'sectionProp',
      name: '时段占比',
      width: 80,
      align: 'center',
      render: fmtPer,
    },
    {
      code: 'priceDiffSum',
      name: '价差总值',
      width: 100,
      align: 'center',
      render: fmtPrice,
    },
    {
      code: 'reason',
      name: '原因分析',
      width: 300,
      render: fmtReason,
    },
    {
      code: 'history',
      name: '历史占比',
      width: 80,
      align: 'center',
      render: fmtPer,
    },
  ];
};
